﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static ZK.Common.IConfig;

namespace ZK.Common
{
    public class IConfig: ConfigurationSection
    {
        [ConfigurationProperty("teacher", IsRequired = true)]
        public Teacher TeacherE
        {
            get { return (Teacher)this["teacher"]; }
        }
        public class Teacher : ConfigurationElement
        {
            [ConfigurationProperty("a", IsRequired = true)]
            public string A
            {
                get { return this["a"].ToString(); }
                set { this["a"] = value; }
            }

            [ConfigurationProperty("b", IsRequired = true)]
            public string B
            {
                get { return this["b"].ToString(); }
                set { this["b"] = value; }
            }

            [ConfigurationProperty("c", IsRequired = true)]
            public string C
            {
                get { return this["c"].ToString(); }
                set { this["c"] = value; }
            }
        }
        public static Teacher GetSetTeacher
        {
            get { return ((IConfig)ConfigurationManager.GetSection("IConfig")).TeacherE; }
            set {
                Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
                IConfig iConfig = config.GetSection("IConfig") as IConfig;
                iConfig.TeacherE.A = value.A;
                //config.SaveAs("ZK.CoalYardTransManage.exe.Config");//重新保存到某xml（一般默认在当前项目下的xml中）
                config.Save(ConfigurationSaveMode.Modified);
                ConfigurationManager.RefreshSection("IConfig");
            }
        }

    }
   
}
